<?php
    require_ONCE("global.php");
    require_ONCE("HttpApi.php");
    
    $userid = $_GET["ownerid"];
    $parentid = $_GET["parentid"];
    $name = $_GET["name"];
    $version = $_GET["version"];
    
    $url = 'http://'.$DS_HOST.'/'.$userid.'/'.$parentid.'/readfile?name='.$name.'&version='.$version;
    
    //echo $url;
    $http = new HttpApi();
    $params = Array(
        //"name" => $name,
    );
    
    $result = $http->makeRequest($url, $params);
    //echo strlen($result);
    header("Content-Type:application/octet-stream");
    header("Content-Disposition:attachment");
    echo ($result);
    $parentname = getdirname($userid, $parentid);
    oplog($userid, $_SESSION['user']["id"], $_SESSION['user']["name"], "browser", $parentname, "web", $name, NULL, "download file ".$name. " in directory ".$parentname);
?>
